﻿using FastEndpoints;
using FluentValidation;
using vite_core.Common;
using vite_entity.Entities;

namespace vite_net.Controllers.User.AddUser
{
    public class Model
    {
        public sealed class Request
        {
            //public string? Avatar { get; set; }
            //public string? DeptCode { get; set; }
            //public string? Email { get; set; }
            //public int? GenderKey { get; set; }
            //public string? Mobile { get; set; }
            //public string? Nickname { get; set; }
            //public string? Username { get; set; }
            //public string[]? RoleCodes { get; set; }
            //public int Id { get; set; }
            //public int Status { get; set; }

            public int Id { get; set; }
            public string? Avatar { get; set; }
            public DateTime? CreateTime { get; set; }
            public string? DeptCode { get; set; }
            public string? DeptName { get; set; }
            public string? Email { get; set; }
            public int? GenderKey { get; set; }
            public string? GenderLabel { get; set; }
            public string? Mobile { get; set; }
            public string? NickName { get; set; }
            public string[] RoleCodes { get; set; }
            public string? RoleNames { get; set; }
            public int Status { get; set; }
            public string? UserName { get; set; }


            public sealed class EditUserValidator : Validator<Request>
            {
                public EditUserValidator()
                {
                    

                    RuleFor(x => x.DeptCode)
                        .NotEmpty()
                        .WithMessage("部门信息是必须的!");
                }
            }

        }




        public sealed class Response
        {
            public string? Msg { get; set; }
            public int Code { get; set; }
        }



        public sealed class UserMapper : Mapper<Request, Response, SysUser>
        {
            // public IBaseRepository<SysDept> _baseSysDeptRepository { get; set; }
            public override SysUser ToEntity(Request r) => new()
            {
                Username = r.UserName,
                Nickname = r.NickName,
                Gender = r.GenderKey == 0 ? false : true,
                Password = "123456".ToMD5(),
                DeptId = 1,
                Avatar = r.Avatar,
                Mobile = r.Mobile,
                Status = r.Status == 0 ? false : true,
                Email = r.Email,
                CreateTime = DateTime.Now,
                CreateBy = 1,
                IsDeleted = false
            };


            /// <summary>
            /// 逻辑删除标识(0-未删除 1-已删除)
            /// </summary>
            public bool? IsDeleted { get; set; }

            public override Response FromEntity(SysUser e) => new()
            {
                //Id = e.Id,
                //FullName = e.FullName,
                //UserName = $"USR{e.Id:0000000000}",
                //Age = (DateOnly.FromDateTime(DateTime.UtcNow).DayNumber - e.DateOfBirth.DayNumber) / 365,
            };
        }

    }
}
